package itsm.isperp.module.service.knowledge;

import itsm.isperp.framework.core.context.ContextHolder;
import itsm.isperp.framework.data.commons.repository.BaseRepository;
import itsm.isperp.framework.service.BaseService;
import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.module.entity.knowledge.KngMyfavorite;
import itsm.isperp.module.repository.knowledge.KngMyfavoriteMapper;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class KngMyfavoriteService extends BaseService<KngMyfavorite> {

	@Autowired
	protected KngMyfavoriteMapper kngMyfavoriteMapper;

	@Override
	public BaseRepository<KngMyfavorite> getRepository() {
		return this.kngMyfavoriteMapper;
	}

	public List<Map<String, Object>> getMyfavoriteItem(String loginUserAccount) {
		return kngMyfavoriteMapper.getMyfavoriteItem(loginUserAccount);

	}

	public boolean isInMyfavitor(String knowledgeId) {

		JqGridRequest req = new JqGridRequest();
		req.isQueryOne(true);
		req.setSelectColumns("id");
		req.addFilterRule("loginUserAccount", JqGridFilterRuleOp.eq,
				ContextHolder.getLoginUsername());
		req.addFilterRule("knowledgeItemid", JqGridFilterRuleOp.eq, knowledgeId);

		List<KngMyfavorite> list = this.findAll(req);
		if (list != null && list.size() > 0) {
			return true;
		}

		return false;
	}

}
